package com.puppet.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutModelConfig {

    /*
    * 创建广播交换机
    * */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");//交换机名称
    }

    /*
    * 创建两个队列
    * */
    @Bean
    public Queue FanoutQueue1(){
        return new Queue("fanoutQueue1");
    }

    @Bean
    public Queue FanoutQueue2(){
        return new Queue("fanoutQueue2");
    }

    //将队列绑定到交换机
    @Bean
    public Binding fanoutBinding1(Queue FanoutQueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(FanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding fanoutBinding2(Queue FanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(FanoutQueue2).to(fanoutExchange);
    }
}
